{% extends "base/base_layout.html" %}
{% load static %}
{% block sidebar_option %}
    sidebar-mini
{% endblock %}
{% block extra_css %}
    <!-- DataTables -->
    <link rel="stylesheet" href="{% static "adminlte/plugins/datatables-bs4/dataTables.bootstrap4.min.css" %}">
    <style type="text/css" media="print">
        @page {
            size: landscape;
        }

        @media print {
            .btn, #scan_options {
                display: none;
            }
        }
    </style>
    <style>
        #app_icon {
            width: 64px;
            height: 64px;
        }
    </style>
{% endblock %}
{% block sidebar %}
    <!-- Main Sidebar Container -->
    <!-- Sidebar -->
    <div class="sidebar">
        <!-- Sidebar user panel (optional) -->
        <div class="user-panel mt-3 pb-3 mb-3 d-flex">
            <div class="info">
                <a href="#" class="d-block">Static Analyzer</a>
            </div>
        </div>

        <!-- Sidebar Menu -->
        <nav class="mt-2">
            <ul class="nav nav-pills nav-sidebar flex-column nav-child-indent" data-widget="treeview" role="menu"
                data-accordion="false">

                <li class="nav-item">
                    <a href="#information" class="nav-link">
                        <i class="nav-icon fas fa-info-circle"></i>
                        <p>
                            Information
                        </p>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="#scan_options" class="nav-link">
                        <i class="nav-icon fas fa-cog"></i>
                        <p>
                            Scan Options
                        </p>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="#binary_analysis" class="nav-link">
                        <i class="nav-icon fas fa-flag"></i>
                        <p>
                            Binary Analysis
                        </p>
                    </a>
                </li>
                {% if virus_total %}
                    <li class="nav-item">
                        <a href="#virus_total" class="nav-link">
                            <i class="fas fa-spider nav-icon"></i>
                            <p>VirusTotal</p>
                        </a>
                    </li>
                {% endif %}
                <li class="nav-item">
                    <a href="#files" class="nav-link">
                        <i class="nav-icon far fa-copy"></i>
                        <p>
                            Files
                        </p>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="../pdf/?md5={{ md5 }}" class="nav-link">
                        <i class="nav-icon fas fa-file-pdf"></i>
                        <p>
                            PDF Report
                        </p>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="javascript:window.print()" class="nav-link">
                        <i class="nav-icon fa fa-print"></i>
                        <p>
                            Print Report
                        </p>
                    </a>
                </li>
            </ul>
        </nav>
        <!-- /.sidebar-menu -->
    </div>
    <!-- /.sidebar -->
{% endblock %}
{% block content %}
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <div class="content-header">
            <!--
              <div class="container-fluid">
                <div class="row mb-2">
                  <div id="mobsf_header" align="center">
                  </div>
                </div>
              </div>-->
        </div>
        <!-- /.content-header -->


        <!-- Main content -->
        <a id="information" class="anchor"></a>
        <section class="content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">

                        <div class="card">
                            <div class="card-body">
                                <h5 class="card-title"></h5>
                                <div class="row">
                                    <div class="col-2">
                                        <p><strong><i class="fas fa-info"></i> APP INFORMATION </strong></p>
                                        <span class="badge bg-primary">App Name</span>
                                        {{ app_name }} <br/>
                                        <span class="badge bg-primary">Publisher</span>
                                        {{ publisher_name }} <br/>
                                        <span class="badge bg-primary">Version</span>
                                        {{ app_version }} <br/>
                                        <span class="badge bg-primary">Arch</span>
                                        {{ architecture }}
                                        {% if virus_total and virus_total.items|length > 9 %}
                                            {% if virus_total.positives > 0 %}
                                                <span class="badge bg-danger">VirusTotal Detection</span>
                                                <strong>{{ virus_total.positives }}/{{ virus_total.total }}</strong>
                                                <br/>
                                            {% else %}
                                                <span class="badge bg-success">VirusTotal Detection</span>
                                                <strong>{{ virus_total.positives }}/{{ virus_total.total }}</strong>
                                                <br/>
                                            {% endif %}
                                        {% endif %}
                                    </div>
                                    <div class="col-5">
                                        <p><strong><i class="fas fa-box-open"></i> FILE INFORMATION </strong></p>
                                        <span class="badge bg-primary">File Name</span>
                                        {{ file_name }} <br/>
                                        <span class="badge bg-primary">Size</span>
                                        {{ size }} <br/>
                                        <span class="badge bg-primary">MD5</span>
                                        {{ md5 }} <br/>
                                        <span class="badge bg-primary">SHA1</span>
                                        {{ sha1 }} <br/>
                                        <span class="badge bg-primary">SHA256</span>
                                        {{ sha256 }}
                                        </p>
                                    </div>
                                    <div class="col-5">
                                        <p><strong><i class="fas fa-file-code"></i> XML INFORMATION </strong></p>
                                        <span class="badge bg-primary">Compiler Version</span>
                                        {{ compiler_version }}
                                        <span class="badge bg-primary">Visual Studio Version</span>
                                        {{ visual_studio_version }} <br/>
                                        <span class="badge bg-primary">Visual Studio Edition</span>
                                        {{ visual_studio_edition }} <br/>
                                        <span class="badge bg-primary">Target OS</span>
                                        {{ target_os }} <br/>
                                        <span class="badge bg-primary">APPX DLL Version</span>
                                        {{ appx_dll_version }} <br/>
                                        <span class="badge bg-primary">Proj GUID</span>
                                        {{ proj_guid }} <br/>
                                        <span class="badge bg-primary">Opti Tool</span>
                                        {{ opti_tool }} <br/>
                                        <span class="badge bg-primary">Target Run</span>
                                        {{ target_run }}
                                    </div>


                                </div>

                            </div>
                        </div>
                    </div>
                    <!-- /.col -->
                    <!-- row and container-->
                </div>
            </div>
        </section>
        <!-- =========================end information==================================== -->


        <a id="scan_options" class="anchor"></a>
        <section class="content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-body">
                                <p>
                                    <strong><i class="fas fa-cog"></i> SCAN OPTIONS</strong>
                                </p>
                                <p align="center">
                                    <a href="../static_analyzer_windows/?checksum={{ md5 }}&amp;name={{ file_name }}&amp;type=appx&amp;rescan=1"
                                       class="btn btn-info" role="button"><i class="fa fa-sync"></i> Rescan</a>
                                    <a href="#" data-target="#mstrings" role="button" class="btn btn-primary"
                                       data-toggle="modal"><i class="fa fa-list"></i> View Strings</a>
                                </p>
                            </div>
                        </div><!-- /.card -->
                    </div>
                    <!-- end row -->
                </div>
            </div>
        </section>

        <a id="binary_analysis" class="anchor"></a>
        <section class="content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-body">
                                <p>
                                    <strong><i class="fas fa-flag"></i> APPX BINARY ANALYSIS</strong>
                                </p>
                                <div class="table-responsive">
                                    <table class="table table-bordered table-hover table-striped">
                                        <thead>
                                        <tr>
                                            <th>ISSUE</th>
                                            <th>STATUS</th>
                                            <th>DESCRIPTION</th>
                                            <th>INFO</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        {% for result in binary_analysis %}
                                            <tr>
                                                <td>{{ result.rule_id }}</td>
                                                <td>
                                                    {% if result.status == "Insecure" %}
                                                        <span class='badge bg-danger'>
                                                    {% endif %}
                                                    {% if result.status == "Secure" %}
                                                        <span class='badge bg-success'>
                                                    {% endif %}
                                                    {% if result.status == "Info" %}
                                                        <span class='badge bg-info'>
                                                    {% endif %}
                                                    {{ result.status }}
                                                    </span>
                                                </td>
                                                <td>{{ result.desc }}</td>
                                                <td>{{ result.info }}</td>
                                            </tr>
                                        {% endfor %}
                                        {% for warn in binary_warnings %}
                                            <tr>
                                                <td>{{ warn.rule_id }}</td>
                                                <td>
                          <span class='badge bg-info'>
                            {{ warn.status }}
                        </span>
                                                </td>
                                                <td>{{ warn.desc }}</td>
                                                <td>{{ warn.info }}
                                            </tr>
                                        {% endfor %}
                                        </tbody>
                                    </table>
                                </div>

                            </div>
                        </div><!-- /.card -->
                    </div>
                    <!-- end row -->
                </div>
            </div>
        </section>
        <!-- ===========================end binary analysis ================================== -->
        {% if virus_total %}
            <a id="virus_total" class="anchor"></a>
            <section class="content">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-lg-12">
                            <div class="card">
                                <div class="card-body">
                                    <p>
                                        <strong><i class="fas fa-spider"></i> VIRUSTOTAL SCAN</strong>
                                    </p>
                                    <div class="table-responsive">
                                        {% if virus_total.items|length < 9 %}
                                            {% comment %} Basic check to determine if the response is a msg or a result {% endcomment %}
                                            <p align="left">&nbsp;&nbsp;<strong>{{ virus_total.verbose_msg }}</strong>
                                            </p>
                                        {% else %}
                                            <p align="left">&nbsp;&nbsp;<strong> {{ virus_total.positives }}
                                                / {{ virus_total.total }}&nbsp; AVs found this file Malicious! </strong>
                                                &nbsp;&nbsp;<a href="{{ virus_total.permalink }}" target="_blank"
                                                               rel="noopener"><i class="fas fa-th-list"></i> Full Report</a>
                                            </p>
                                            {% if virus_total.positives > 0 %}
                                                <table id="table_vt"
                                                       class="table table-bordered table-hover table-striped">
                                                    <thead>
                                                    <tr>
                                                        <th>AV</th>
                                                        <th>DETECTION</th>
                                                    </tr>
                                                    </thead>
                                                    <tbody>
                                                    {% for av_name,av_result in virus_total.scans.items %}
                                                        {% if av_result.detected == True %}
                                                            <tr>
                                                                <td>
                                                                    {{ av_name }}
                                                                </td>
                                                                <td>
                                                                    <span class="badge bg-danger">{{ av_result.result }}</span>
                                                                </td>
                                                            </tr>
                                                        {% endif %}
                                                    {% endfor %}
                                                    </tbody>
                                                </table>
                                            {% endif %}{% comment %} if results.positive > 0 {% endcomment %}
                                        {% endif %}{% comment %} if this is the upload msg or a result {% endcomment %}
                                    </div>
                                </div>
                            </div><!-- /.card -->
                        </div>
                        <!-- end row -->
                    </div>
                </div>
            </section>
        {% endif %}
        <!-- ===========================end virus total ================================== -->
        <a id="files" class="anchor"></a>
        <section class="content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-body">
                                <p>
                                    <strong><i class="far fa-copy"></i> FILES</strong>
                                </p>
                                <div class="list-group">
                                    <p>
                                        {% for file in files %}
                                            {{ file }} <br>
                                        {% endfor %}
                                    </p>
                                </div>
                            </div>
                        </div>
                    </div><!-- /.card -->
                </div>
                <!-- end row -->
            </div>
        </section>
        <!-- ===========================end files ================================== -->
        <!-- end of contents -->
    </div>

    <!-- Modal -->

    <div class="modal" id="mstrings" tabindex="-1" role="dialog">
        <div class="modal-dialog modal-xl">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title">Strings</h4>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                </div>
                <div class="modal-body">
           <pre><code>
           {% for string in strings %}
               {{ string | safe }}
           {% endfor %}
          </code></pre>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>


{% endblock %}
<!--end new UI-->
{% block extra_scripts %}
    <!-- DataTables -->
    <script src="{% static "adminlte/plugins/datatables/jquery.dataTables.min.js" %} "></script>
    <script src="{% static "adminlte/plugins/datatables-bs4/dataTables.bootstrap4.min.js" %}"></script>
    <script>
        $(function () {
            // Datatable
            $('table').DataTable({
                "paging": true,
                "lengthChange": false,
                "searching": true,
                "ordering": true,
                "info": true,
                "autoWidth": true,
                "responsive": true,
            });
        });
        // Navbar Active
        $(".nav-link").on("click", function () {
            $(".nav-link").removeClass("active");
            $(this).addClass("active");
        });
    </script>
{% endblock %}